package com.example.shixi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.shixi.pojo.Book;
import com.example.shixi.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private IBookService service;

    @GetMapping
    public List<Book> getAllBook(){

        return service.list();
    }

    @GetMapping("{id}")
    public Book getBookById(@PathVariable("id") Integer id){

        return service.getById(id);
    }

    @GetMapping("/{current}/{size}")
    public IPage getPage(@PathVariable("current") Integer current, @PathVariable("size")Integer size){

        return service.getPage(current,size);
    }


    @DeleteMapping("{id}")
    public boolean deleteBook(@PathVariable("id") Integer id){

        return service.removeById(id);
    }

    @PutMapping()
    public boolean updateBook(@RequestBody Book book){

        return service.updateById(book);
    }

    @PostMapping()
    public boolean saveBook(@RequestBody Book book){

        return service.save(book);
    }
}
